package com.itheima.controller;

import com.itheima.dto.MediaNewsDto;
import com.itheima.dto.PubishNewsDto;
import com.itheima.service.NewsService;
import com.itheima.vo.MediaNewsVo;
import com.itheima.vo.PagingQueryVo;
import com.itheima.vo.Result;
import net.sourceforge.tess4j.TesseractException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * @author :wujunjie
 * createTime :2023-01-02 23:02
 * description :
 */
@RestController
@RequestMapping("/api/v1/news")
public class NewsController {
    @Autowired
    private NewsService newsService;
    @PostMapping("/list")
    public Result selectNews(@RequestBody MediaNewsDto dto){
        PagingQueryVo<MediaNewsVo> pagingQueryVo=newsService.selectNews(dto);
        return Result.mediaNewsSuccess(pagingQueryVo);
    }

    @PostMapping("/submit")
    public Result pubishNews(@RequestBody PubishNewsDto dto) throws TesseractException, IOException {
        Boolean publish=newsService.pubishNews(dto);
        if (publish){
            return Result.success();

        }
        return Result.error();
    }

    @PostMapping("/down_or_up")
    public Result newsDDownOrUp( ){
        Long id=newsService.newsDDownOrUp();

            return Result.success(id);

    }
}
